/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.PurchaseHistory;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Hadi
 */
@Repository
public class PurchaseHistoryDao {
    @Autowired private SessionFactory sessionFactory;

    public void save(PurchaseHistory ph){
        sessionFactory.getCurrentSession().saveOrUpdate(ph);
    }

    public void delete(PurchaseHistory ph){
        sessionFactory.getCurrentSession().delete(ph);
    }

    public PurchaseHistory findById(Long id){
        return (PurchaseHistory) sessionFactory.getCurrentSession().get(PurchaseHistory.class, id);
    }

    public List<PurchaseHistory> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from PurchaseHistory").list();
    }

}
